﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PRET.ReportControlLib.Controls
{
    public partial class TeamAttendanceFilter : UserControl
    {
        public event ShowTeamAttendanceReportViewEventHandle showReportEvent;

        public TeamAttendanceFilter()
        {
            InitializeComponent();
            InitializeYearsMonths();
        }
        private void InitializeYearsMonths()
        {
            this.dateTimePicker.MaxDate = DateTime.Today;
            this.dateTimePicker.Value = DateTime.Today;
        }

        public DateTime GetSelectedYearMonth
        {
            get
            {
                string yearmonth = this.dateTimePicker.Value.ToString("yyyy-MM");
                return DateTime.Parse(yearmonth);
            }
        }

        public void EnableControls(bool sign)
        {
            this.dateTimePicker.Enabled = sign;
            this.reportViewBtn.Enabled = sign;
        }

        private void reportViewBtn_Click(object sender, EventArgs e)
        {
            if (showReportEvent != null)
            {
                ShowTeamAttendanceReportViewEventArgs eventArg = new ShowTeamAttendanceReportViewEventArgs();
                eventArg.Month = this.GetSelectedYearMonth;
                showReportEvent(this, eventArg);
            }
        }
    }

    public delegate void ShowTeamAttendanceReportViewEventHandle(object sender, ShowTeamAttendanceReportViewEventArgs args);
    public class ShowTeamAttendanceReportViewEventArgs : EventArgs
    {
        public ShowTeamAttendanceReportViewEventArgs()
        { }
        private DateTime month;

        public DateTime Month
        {
            get { return month; }
            set { month = value; }
        }
    }
}
